package com.example.john.adaptertest;

import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private ListView lv;
    private List<Item> items;
    private List<byte[]> snaps=new ArrayList<byte[]>();
    private String[] u=new String[]{"a1","a2","a3"};
    private Handler h;

    private void initData(){

        items=new ArrayList<Item>();
        for(int i=0;i<snaps.size();i++){
            Item item=new Item();
            item.setContent("Content....."+i);
            item.setTitle("Title." + i);
            item.setSnap(snaps.get(i));
            items.add(item);
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        lv=(ListView)findViewById(R.id.lv1);
       h=new Handler(){
            @Override
            public void handleMessage(Message msg) {
                LayoutInflater inflater=getLayoutInflater();
                MyBaseAdapter ma=new MyBaseAdapter(items,inflater);
                lv.setAdapter(ma);
            }
        };

        new Thread(){
            @Override
            public void run() {
                for(String s:u){
                    String url="http://192.168.10.214:8080/StuMs/tes1?fn="+s;
                    byte[] data=ImageViewUtil.decode(url,10240,256);
                    snaps.add(data);

                }
                initData();
                h.sendMessage(new Message());
            }
        }.start();









    }


}
